<template>
  <div class="main">
    <img class="banner one" src="../../static/di tu yi/ditu_zuo.jpeg" alt="">
    <img class="banner two" src="../../static/di tu yi/ditu_youshang.jpeg" alt="">
    <div class="main_info">
      <div class="user">
        <div class="avatar">
          <img src="/static/img/avatar.png" alt="">
        </div>
        <div class="name">
          <div class="username">{{ info.nickName }}</div>
          <div class="signature">欢迎使用 AI智能人岗匹配系统</div>
        </div>
      </div>
      <div class="nums">
        <div class="box">
          <div><span class="num">0</span></div>
          <div>余数</div>
        </div>
        <span>|</span>
        <div class="box">
          <div>￥<span class="num">0</span></div>
          <div>余额</div>
        </div>
      </div>
      <div class="menu">
        <div class="item">
          <div class="left" :class="[itemShow0 && 'active']" @click="toggleItem(0)">
            <div class="menuName">我的简历列表<block v-if="itemShow0">（点击使用简历）</block><u-icon :name="itemShow0 ? 'arrow-down' : 'list'" :color="itemShow0 ? '#8466d3' : '#ffffff'" size="16"></u-icon></div>
          </div>
          <scroll-view class="bottom" scroll-y="true" v-if="itemShow0">
            <div class="item_content" v-for="(item,index) in data[0]" :key="index">
              <div class="item_left nowarp">{{ item.resumeName || info.nickName }}</div>
              <div class="item_center copy" @click="useItem(item.id)">使用</div>
              <div class="item_right">{{ item.createTime }}</div>
            </div>
          </scroll-view>
        </div>
        <div class="item">
          <div class="left" :class="[itemShow1 && 'active']" @click="toggleItem(1)">
            <div class="menuName">匹配记录<block v-if="itemShow1">（点击复制下载链接）</block><u-icon :name="itemShow1 ? 'arrow-down' : 'order'" :color="itemShow1 ? '#8466d3' : '#ffffff'" size="16"></u-icon></div>
            <div v-if="!itemShow1">查看导出的PDF信息列表</div>
          </div>
          <scroll-view class="bottom" scroll-y="true" v-if="itemShow1">
            <div class="item_content" v-for="(item,index) in data[1]" :key="index">
              <div class="item_left nowarp">{{ item.createBy || info.nickName }}</div>
              <div class="item_center copy" @click="copyOrder(item.pdfUrl)">复制</div>
              <div class="item_right">{{ item.createTime }}</div>
            </div>
          </scroll-view>
        </div>
        <div class="item">
          <div class="left" :class="[itemShow2 && 'active']" @click="toggleItem(2)">
            <div class="menuName">付费记录<u-icon :name="itemShow2 ? 'arrow-down' : 'order'" :color="itemShow2 ? '#8466d3' : '#ffffff'" size="16"></u-icon></div>
            <div v-if="!itemShow2">查看购买的订单信息列表</div>
          </div>
          <scroll-view class="bottom" scroll-y="true" v-if="itemShow2">
            <block v-for="(item,index) in data[2]" :key="index">
              <div class="item_content" v-if="['2', '7'].includes(item.orderStatus)">
                <div class="item_left">
                  <div class="orderNumber" v-if="item.outTradeNo">订单号：<text :selectable="true">{{ item.outTradeNo || '' }}</text></div>
                  <div class="orderNumber" v-else-if="item.redemptionCode">兑换码：<text :selectable="true">{{ item.redemptionCode || '' }}</text></div>
                  <div class="orderNumber" v-else></div>
                  <div class="name">{{ item.createBy || info.nickName }}</div>
                </div>
                <div class="item_right">
                  <div class="status">{{ item.status }}</div>
                  <div class="time">{{ item.createTime }}</div>
                </div>
              </div>
            </block>
          </scroll-view>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getMyList, useResume } from '@/api/detail/detail.js'
export default {
  data() {
    return {
      info: {},
      data: [[], [], []],
      itemShow0: false,
      itemShow1: false,
      itemShow2: false,
      current: ''
    }
  },
  created() {
    this.getInfo();
    this.init();
  },
  methods: {
    async init() {
      const res = await getMyList()
      this.data = res.map(v => v.data)
      console.log(this.data);
    },
    async getInfo() {
      this.info = JSON.parse(uni.getStorageSync('userInfo'))
    },
    toggleItem(num) {
      if (this.current === num) {
        this['itemShow' + num] = false
        this.current = '';
        return
      }
      this.current = num;
      for (let i = 0; i < 3; i++) {
        if (i === num) {
          this['itemShow' + i] = true
        } else {
          this['itemShow' + i] = false
        }
      }
    },
    copyOrder(str) {
      uni.setClipboardData({
			  data: str,
			  success: function () {
          uni.showToast({
            title: '复制成功，请在外部浏览器手动粘贴访问和下载',
            icon: 'none'
          })
			  },
			  fail:function () {
          uni.showToast({
              title: '复制失败',
              icon: 'none'
          });
			  }
      });
    },
    async useItem(id) {
      const { data } = await useResume(id)
      let obj = {}
      for (let key in data) {
        data[key] && (obj[key] = data[key])
      }
      uni.showToast({
        title: '简历使用成功',
        icon: 'none'
      })
      uni.setStorageSync('Center_useitem', JSON.stringify(obj))
    }
  }
}
</script>

<style lang="scss" scoped>
.main {
  position: relative;
  height: calc(96vh - 100rpx);
  font-size: 26rpx;
  overflow: hidden;
  box-sizing: border-box;

  .banner {
    position: absolute;
    width: 80rpx;
    height: 80rpx;
    overflow: hidden;

    &.one {
      left: 0;
      top: 0;
    }

    &.two {
      width: 100rpx;
      height: 150rpx;
      right: 0;
      top: 0;
    }

    &.three {
      width: 400rpx;
      height: 220rpx;
      left: 0;
      bottom: -80rpx;
    }

    &.fore {
      width: 300rpx;
      height: 200rpx;
      right: 0rpx;
      bottom: -70rpx;
    }
  }

  .main_info {
    display: flex;
    flex-direction: column;
    padding: 200rpx 48rpx;
    gap: 32rpx;
    .user {
      display: flex;
      align-items: center;
      gap: 32rpx;
      padding: 0 32rpx;
      .avatar {
        border-radius: 50%;
        width: 100rpx;
        height: 100rpx;
        border: 1rpx solid #ccc;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .name {
        font-size: 26rpx;
        .username {
          font-weight: 600;
          font-size: 34rpx;
        }
        .signature {
          color: #ccc;
        }
      }
    }
    .nums {
      background-color: #fff;
      border: 1rpx solid #ccc;
      display: flex;
      align-items: center;
      border-radius: 32rpx;
      padding: 32rpx;
      >span {
        color: #c2abfc;
      }
      .box {
        flex: 1;
        display: flex;
        flex-direction: column;
        font-size: 26rpx;
        align-items: center;
        font-weight: 600;
        .num {
          font-size: 38rpx;
        }
      }
    }
  }

  .menu {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 20rpx;
    position: relative;
    z-index: 99;
    .item {
      flex: 1;
      display: flex;
      flex-direction: column;
      background-color: #7542f9;
      border-radius: 32rpx;
      color: #FFFFFF;
      box-shadow: 0px 4px 10px #ccc;
      overflow: hidden;
      .left {
        display: flex;
        flex-direction: column;
        gap: 4rpx;
        font-size: 26rpx;
        width: 100%;
        padding: 32rpx 24rpx;
        box-sizing: border-box;
        &.active {
          background-image: linear-gradient(#7542f9, #FFFFFF);
          color: #4824a0;
        }
        .menuName {
          font-weight: 600;
          font-size: 30rpx;
          display: flex;
          justify-content: space-between;
        }
      }
      .bottom {
        background-color: #fff;
        max-height: 15vh;
        color: #000;
        box-sizing: border-box;
        padding-bottom: 10rpx;
        .item_content {
          margin: 0 32rpx;
          padding: 14rpx 0;
          display: flex;
          justify-content: space-between;
          align-items: center;
          border-bottom: 1rpx solid #e1e1e1;
          .item_left {
            &.nowarp {
              width: 30%;
              overflow: hidden;
            }
          }
          .orderNumber,
          .status {
            color: #d3d3d3;
            font-size: 20rpx;
            text-align: right;
            max-width: 300rpx;
            white-space: nowrap;
          }
          .name,
          .time {
            font-weight: 600;
          }
          .copy {
            color: #7542f9;
          }
        }
      }
    }
  }
}

/deep/ ::-webkit-scrollbar {
  /*滚动条整体样式*/
  width: 4px !important;
  height: 1px !important;
  overflow: auto !important;
  background: #ccc !important;
  -webkit-appearance: auto !important;
  display: block;
}

/deep/ ::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 10px !important;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
  background: #7b7979 !important;
}

/deep/ ::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  // box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
  // border-radius: 10px !important;
  background: #FFFFFF !important;
}
</style>